<template>
	<view class="container">
		<head>
			<view class="top">
				<view class="left">
					<p>
						<!-- <text>第{{leave}}级</text> -->
						<text>题库{{questionInfo.bankId}}</text>
					</p>
					<!-- <p class="t">
						<text>00:08:38</text>
					</p> -->
				</view>
				<view class="right">
					<p><text class="l">{{questionInfo.current+1}}</text>/<text>{{questionInfo.questionNums}}</text></p>
				</view>
			</view>
			<view class="uni-title uni-common-mt uni-common-pl" style="font-size: 14px;">
				{{questionInfo.current+1}}.{{questionInfo.questionStem}}</view>
			<view class="uni-list">
				<checkbox-group @change="checkboxChange">
					<label v-for="item in questionInfo.optionDtos" :key="index" class="uni-list-cell uni-list-cell-pd" style="display: flex;justify-content: space-between;">
						<view style="font-size: 14px;">{{item.option}}</view>
						<view>
							<checkbox :value="item.option.substring(0,1) " :checked="(item.selected==null || item.selected==0)?false:true" />
						</view>
					</label>
				</checkbox-group>
			</view>
			<!-- <button class="b-s" @click="lastone" v-show="flag">上一题</button>
				<button class="b-s" @click="returnindex" v-show="!flag">返回首页</button>
				<button class="b-s" @click="nextone" v-show="flag"><text>下一题</text></button>
				<button class="b-s" @click="Score" v-show="!flag"><text>交卷</text></button> -->
			
		</head>
		<body>
			<view style="height: 60px;width: 100%;background-color: #CCE6FF;position: fixed;bottom: 0;text-align: center;">
				<button type="default" size="mini" @click="lastone" v-show="!questionInfo.first">上一题</button>
				<button type="default" size="mini" @click="nextone" v-show="!endFlag"><text>下一题</text></button>
				<button type="default" size="mini" @click="Score" v-show="endFlag"><text>交卷</text></button>
			</view>
		</body>
	</view>
</template>
<script>
	import {
		start,
		next,
		last,
		result
	} from '../../apis'

	export default {
		data() {
			return {
				// testHour: 0,
				// testMinute: 0,
				// testSecond: 0,
				flag: true,
				questionInfo: {},
				nextList: {
					answers: '',
					examId: 0,
					questionId: ''
				},
				endFlag: false
			}
		},
		onLoad(option) {
			uni.showLoading({
				title: '加载中'
			});
			//console.log(option.examId)
			this.nextList.examId = option.examId
			console.log("跳转后examId为：" + option.examId)
			console.log("跳转后题目为：")
			console.log(JSON.parse(option.questionInfo))
			this.questionInfo = JSON.parse(option.questionInfo);
			uni.hideLoading();
			// console.log("进入到next页面，题目是")
			// console.log(this.questionInfo)
			// setTimeout(() => {
			// 	this.testHour = 1
			// 	this.testMinute = 1
			// 	this.testSecond = 0
			// }, 2000)
		},
		methods: {
			// timeup() {
			// 	this.flag = false
			// 	uni.showToast({
			// 		title: '时间到',
			// 		image:"../../static/gantan.png"
			// 	})
			// },
			checkboxChange(e) {
				this.nextList.answers = e.detail.value.join(',')
			},
			nextone() {
				next({
					"answers": this.nextList.answers,
					"examId": this.nextList.examId,
					"questionId": this.questionInfo.questionId,
				}).then((res) => {
					let [err, data] = res
					if (data.data.code == 200) {
						//this.flag = true
						console.log('跳转后examid')
						console.log(this.nextList.examId)
						console.log('跳转前题目')
						console.log(data.data.data)
						//this.questionInfo = data.data.data;
						uni.redirectTo({
							url: '../next/next?questionInfo=' + JSON.stringify(data.data.data) + '&examId=' + this.nextList.examId

						});
					} else {
						console.log(data.data.message)
						//this.flag = false
						uni.showToast({
							title: '已经是最后一题了！',
							duration: 2000,
							image: '../../static/gantan.png'
						});
						this.endFlag=true;
					}

				})
			},
			lastone() {
				//console.log("examId为："+this.nextList.examId)
				last({
					'examId': this.nextList.examId
				}).then((res) => {
					let [err, data] = res
					//console.log(data.data.data)
					if (data.data.code == 200) {
						uni.redirectTo({
							url: '../next/next?questionInfo=' + JSON.stringify(data.data.data) + '&examId=' + this.nextList.examId

						});
					}
				})
			},
			Score() {
				console.log("ok")
				uni.reLaunch({
					url:'../answerResult/answerResult?examId='+this.nextList.examId
				})
			},
			returnindex() {
				uni.switchTab({
					url: '../index/index'
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.container {

		// .example-body {
		// 	width: 35%;
		// 	flex-direction: column;
		// }
		// .word-btn-white {
		// 	font-size: 18px;
		// 	color: #FFFFFF;
		// }
		.top {
			display: flex;
			justify-content: space-between;
			padding: 10px;

			// border: 1px solid #007AFF;
			.left {
				text {
					margin-right: 20px;
					font-size: 14px;
				}

				.t {
					margin-top: 5px;
				}
			}

			.right {
				.l {
					font-size: 16px;
				}
			}
		}

		.uni-common-mt {
			margin-top: 0;
		}

		button{
			width: 50%;
			height: 100%;
			text-align: center;
			padding-top: 10px;
			box-shadow: 1px 1px 2px #CCCCCC;
			// margin-right: 60px;
			background-color: #CCE6FF;
			color: #fff;
			font-weight: bold;
			font-size: 18px;
		}
	}

	.b-s{
		width: 100%;
	}
	.bom {
		display: flex;
		justify-content: space-between;
	}
</style>
